# tests.py
import asyncio
import redis.asyncio as redis  # 使用redis-py的异步API


async def test_redis_connection():
    try:
        # 创建异步Redis连接
        redis_client = redis.Redis(
            host='192.168.10.143',
            port=6379,
            # password='20050213w',
            decode_responses=True
        )

        # 测试连接
        await redis_client.ping()
        print("Redis连接成功！")

        # 测试读写
        await redis_client.set("test_key", "test_value")
        value = await redis_client.get("test_key")
        print(f"读取值: {value}")

    except Exception as e:
        print(f"连接错误: {e}")


asyncio.run(test_redis_connection())